
import os
import json
from datetime import datetime

base_path = r"E:\GithubPro\noname_server_extension"
folder_name = "云中守望"
folder_path = os.path.join(base_path, folder_name)

today = datetime.now().strftime("%Y/%m/%d")

# 读取info.json
info_path = os.path.join(folder_path, "info.json")
with open(info_path, "r", encoding="utf-8") as f:
    info_data = json.load(f)
    author = info_data.get("author", "未知")
    version = info_data.get("version", "1.0")

# 遍历文件夹获取所有文件路径，并计算大小
file_list = []
total_size_bytes = 0

for root, _, files in os.walk(folder_path):
    for file in files:
        if file == "extension.js":
            continue
        file_path = os.path.join(root, file)
        rel_path = os.path.relpath(file_path, folder_path).replace("\\", "/")
        file_list.append(f'"{rel_path}"')
        total_size_bytes += os.path.getsize(file_path)

size_kb = total_size_bytes / 1024
if size_kb >= 1024:
    size_str = f'{size_kb / 1024:.2f}MB'
else:
    size_str = f'{round(size_kb)}KB'

output = f"""extension["{folder_name}"]={{{{
\tdate:"{today}",
\tintro:"为联机提供便利的扩展，只需房主下载即可，内置多种模式（包含联机PVE）。",
\tauthor:"{author}",
\tnetdisk:"",
\tforum:"",
\tversion:"{version}",
\tfiles:[
\t\t{',\n\t\t'.join(file_list)}
\t],
\tsize:"{size_str}"
}}}};
"""

print(output)